<%--
  Created by IntelliJ IDEA.
  User: Snail Q
  Date: 2017/4/12
  Time: 15:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="/static/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="/js/login.js"></script>
<script type="text/javascript" src="/static/js/jquery.tips.js"></script>
<script type="text/javascript">
    function checkLoginInfo() {
        if ("" == $('#u').val()) {
            $('#u').tips({
                side: 2,
                msg: "用户名不得为空",
                bg: '#AE81FF',
                //time:2 ，默认为2秒显示
            });
            $('#u').focus();
            return false;
        }
        if ("" == $('#p').val()) {
            $('#p').tips({
                side: 2,
                msg: "密码不得为空",
                bg: '#AE81FF',
                //time:2 ，默认为2秒显示
            });
            $('#p').focus();
            return false;
        }
        return true;
    }
    function webLogin() {
        if (checkLoginInfo()) {
            var loginname = $('#u').val();
            var password = $('#p').val();
            $.ajax({//使用jquery下面的ajax开启网络请求
                type: "post",//http请求方式为POST
                url: "/userAction/login",//请求接口的地址
                data: {loginId: loginname, pwd: password},//存放的数据，服务器接口字段为loginId和pwd,分别对应用户登录名和密码
                dataType: 'json',//当这里指定为json的时候，获取到了数据后会自动解析的，只需要返回值，字段名称就可以使用了
                cache: false,//不用缓存
                success: function (data) {//请求成功，http状态码为200，返回的数据已经打包在data中了。
                    if (data.code == 1) {//获判断json数据中的code是否为1，登录的用户名和密码匹配，通过校验，登陆成功
                        window.location.href = data.data.nextUrl;//跳转到主页
                    } else {//登录不成功
                        $('.login_form').tips({
                            side: 2,
                            msg: (data.msg),
                            bg: '#AE81FF',
                            //time:2 ，默认为2秒显示
                        });
                        $('#u').focus();
                    }
                },
                error: function () {
                    alert("尼玛炸了");
                }

            });
        }
    }

    function webReg() {
        if ("" == $('#user').val()) {
            $('#user').focus();
            $('#user').tips({
                side: 2,//右边
                msg: "用户名不能为空",
                bg: '#AE81FF'
            });
            return false;
        }
        if ($('#user').val().length < 4 || $('#user').val().length > 16) {
            $("#user").focus();
            $("#user").tips({
                side: 2,//右边
                msg: "用户名为4-16位字符",
                bg: '#AE81FF'
            });
            return false;
        }
        if ($('#name').val().length < 4 || $('#name').val().length > 16 || "" == $('#name').val()) {
            $("#name").focus();
            $("#name").tips({
                side: 2,//右边
                msg: "用户姓名必须为4-16位字符",
                bg: '#AE81FF'
            });
            return false;
        }
        if ($('#passwd').val().length < 6) {
            $("#passwd").focus();
            $("#passwd").tips({
                side: 2,//右边
                msg: "密码不能小于6位",
                bg: '#AE81FF'
            });
            return false;
        }
        if ($('#passwd2').val() != $('#passwd').val()) {
            $('#passwd2').focus();
            $("#passwd2").tips({
                side: 2,
                msg: '两次密码不一致',
                bg: '#AE81FF',
            });
            return false;
        }
        var sqq = /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
        if (!sqq.test($('#cellNumber').val())
            || $('#cellNumber').val().length < 5
            || $('#cellNumber').val().length > 12
            || $('#cellNumber').val() == "") {

            $('#cellNumber').focus();
            $("#cellNumber").tips({
                side: 2,
                msg: '手机号格式不正确',
                bg: '#AE81FF',
            });
            return false;
        }
        if ($('#sex').val() == "") {
            $('#sex').focus();
            $("#sex").tips({
                side: 2,
                msg: '性别不能为空',
                bg: '#AE81FF',
            });
            return false;
        }
        if ($('#age').val() == "") {
            $('#age').focus();
            $("#age").tips({
                side: 2,
                msg: '年龄不能为空',
                bg: '#AE81FF',
            });
            return false;
        }
        var loginname = $("#user").val();
        var password = $("#passwd").val();
        var username = $("#name").val();
        var cellNumber = $("#cellNumber").val();
        var sex = $("#sex").val();
        var age = $("#age").val();
        $.ajax({
            type: "POST",
            url: "/userAction/reg",
            data: {loginId: loginname, pwd: password, name: username, sex: sex, age: age, cellNumber: cellNumber},
            dataType: 'JSON',
            cache: false,
            success: function (data) {
                if (data.code == 1) {
                    window.location.href = data.data.nextUrl;
                } else {
                    $('#regUser').tips({
                        side: 2,
                        msg: (data.msg),
                        bg: '#AE81FF',
                        //time:2 ，默认为2秒显示
                    });
                    $('#u').focus();
                }
            },
            error: function () {
                alert("尼玛炸了");
            }
        });

    }
</script>
<head>
    <base href="<%=basePath%>"/>
    <title>仓库管理系统→登录</title>
    <meta http-equiv="Content-Type" CONTENT="text/html" charset="UTF-8">
    <link href="/css/login.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<h1>仓库管理系统登录注册<sup>2016</sup></h1>
<div class="login" style="margin-top: 50px;">
    <div class="header">
        <div class="switch" id="switch">
            <a class="switch_btn_focus" id="switch_qlogin" href="javascript:void(0);" tabindex="7">快速登录</a>
            <a class="switch_btn" id="switch_login" href="javascript:void(0);" tabindex="8">快速注册</a>
            <div class="switch_bottom" style="position: absolute;width: 64px;left: 0px;"></div>
        </div>
    </div>
    <div class="web_qr_login" id="web_qr_login" style="display: block;height: 255px">
        <!--登录-->
        <div class="web_login" id="web_login">
            <div class="login-box">
                <div class="login_form">
                    <form action="" name="loginform" accept-charset="UTF-8" id="login_form"
                          class="loginForm" method="post"><input type="hidden" name="did" value="0"/>
                        <input type="hidden" name="to" value="log"/>
                        <div class="uinArea" id="uinArea">
                            <label class="input-tips" for="u">帐号：</label>
                            <div class="inputOuter" id="uArea">
                                <input type="text" id="u" name="loginId" class="inputstyle"/>
                            </div>
                        </div>
                        <div class="pwdArea" id="pwdArea">
                            <label class="input-tips" for="p">密码：</label>
                            <div>
                                <input type="password" id="p" name="pwd" class="inputstyle">
                            </div>
                        </div>
                        <div style="padding-left: 50px;margin-top: 20px;">
                            <input type="button" id="btn_login" value="登 录" onclick="webLogin()" style="width: 150px"
                                   class="button_blue"/>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!--登录End-->
    </div>
    <!--注册-->
    <div class="qlogin" id="qlogin" style="display: none">
        <div class="web_login">
            <form name="form2" id="regUser" accept-charset="utf-8" action="" method="post">
                <input type="hidden" name="to" value="reg"/>
                <input type="hidden" name="did" value="0"/>
                <ul class="reg_form" id="reg-ul">
                    <div id="userCue" class="cue">快速注册请注意格式</div>
                    <li>
                        <label for="user" class="input-tips2">用户名：</label>
                        <div class="inputOuter2">
                            <input type="text" id="user" name="loginId" maxlength="16" class="inputstyle2"/>
                        </div>
                    </li>
                    <li>
                        <label for="name" class="input-tips2">姓名：</label>
                        <div class="inputOuter2">
                            <input type="text" id="name" name="name" maxlength="16" class="inputstyle2"/>
                        </div>
                    </li>
                    <li>
                        <label for="passwd" class="input-tips2">密码：</label>
                        <div class="inputOuter2">
                            <input type="password" id="passwd" name="pwd" maxlength="16" class="inputstyle2">
                        </div>
                    </li>
                    <li>
                        <label for="passwd2" class="input-tips2">确认密码：</label>
                        <div class="inputOuter2">
                            <input type="password" id="passwd2" name="" maxlength="16" class="inputstyle2"/>
                        </div>
                    </li>
                    <li>
                        <label for="cellNumber" class="input-tips2">手机号：</label>
                        <div class="inputOuter2">
                            <input type="text" id="cellNumber" name="cellNumber" maxlength="18" class="inputstyle2"/>
                        </div>
                    </li>
                    <li>
                        <label for="sex" class="input-tips2">性别：</label>
                        <div class="inputOuter2">
                            <input type="text" id="sex" name="sex" maxlength="18" class="inputstyle2"/>
                        </div>
                    </li>
                    <li>
                        <label for="age" class="input-tips2">年龄：</label>
                        <div class="inputOuter2">
                            <input type="age" id="age" name="age" maxlength="18" class="inputstyle2"/>
                        </div>
                    </li>
                    <li>
                        <div class="inputArea">
                            <input type="button" id="reg" style="margin-top: 10px;margin-left: 85px;"
                                   class="button_blue"
                                   onclick="webReg()"
                                   value="同意协议并注册"/><a href="#" class="zcxy" target="_blank">注册协议</a>
                        </div>
                    </li>
                    <div class="cl"></div>
                </ul>
            </form>
        </div>
    </div>
    <!--注册End-->
</div>
<div class="suggest">*推荐使用ie8或以上版本ie浏览器或Chrome内核浏览器访问本站</div>
</body>
</html>
